package com.gdones.bootserver.bus.param.controller;


import com.gdones.bootserver.bus.param.dto.Param;
import com.gdones.bootserver.bus.param.service.IParamService;
import com.gdones.common.core.annotations.MySysLog;
import com.gdones.common.core.annotations.MySysLogOpration;
import com.gdones.common.core.dto.MyPageBand;
import com.gdones.common.core.dto.MyResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *
 * 字典管理
 * @author GaoJingBo
 * @since 2023-03-27
 */
@RestController
@RequestMapping("/sys/param")
@Slf4j
@Api(tags = "字典表操作接口")
public class ParamController {

    @Resource(name = "paramServiceImpl")
    private IParamService paramService;

    /**
     * 字典表分页查询
     * @param param 字典参数
     * @param page 分页参数
     * @return
     */
    @GetMapping("/pages")
    @ApiOperation("字典表分页查询")
    @MySysLog(modelName="字典管理",methodDesc = "字典表分页查询",methodType = MySysLogOpration.GET)
    public MyResult getParamPage(Param param, MyPageBand page){
        log.info("--- 字典管理：字典表分页查询");

        MyResult result = new MyResult();

        try{
            result = paramService.getParamPage(param,page);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("字典表分页系统异常");
            result.setCode("9999");
        }

        return result;
    }

    /**
     * 添加-字典表
     * @param param 字典数据
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加-字典表")
    @MySysLog(modelName="字典管理",methodDesc = "添加-字典表",methodType = MySysLogOpration.POST)
    public MyResult addParam(@RequestBody Param param){
        log.info("--- 字典管理：添加-字典表");

        MyResult result = new MyResult();

        try{
            result = paramService.add(param);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("添加-字典表系统异常");
            result.setCode("9999");
        }

        return result;
    }

    /**
     * 修改-字典表
     * @param param 字典数据
     * @return
     */
    @PutMapping ("/update")
    @ApiOperation("修改-字典表")
    @MySysLog(modelName="字典管理",methodDesc = "修改-字典表",methodType = MySysLogOpration.PUT)
    public MyResult updateParam(@RequestBody Param param){
        log.info("--- 字典管理：修改-字典表");

        MyResult result = new MyResult();

        try{
            result = paramService.update(param);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("修改-字典表系统异常");
            result.setCode("9999");
        }

        return result;
    }

    /**
     * 删除-字典表
     * @param paramIDs 可批量、单独删除的字典id，逗号分隔
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除-字典表")
    @MySysLog(modelName="字典管理",methodDesc = "删除-字典表",methodType = MySysLogOpration.DELETE)
    public MyResult updateParam(String paramIDs){
        log.info("--- 字典管理：删除-字典表");

        MyResult result = new MyResult();

        try{
            result = paramService.delete(paramIDs);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("删除-字典表系统异常");
            result.setCode("9999");
        }

        return result;
    }

    /**
     * 通过字典code查询字典数据
     * @param paramCode 字典编号
     * @return
     */
    @GetMapping("/getParamByCode")
    @ApiOperation("通过字典code查询字典数据")
    @MySysLog(modelName="字典管理",methodDesc = "通过字典code查询字典数据")
    public MyResult getParamByCode(String paramCode){
        log.info("--- 字典管理：通过字典code查询字典数据");

        MyResult result = new MyResult();

        try{
            result = paramService.getParamByCode(paramCode);
            result.setMsg(null);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("字典数据查询系统异常");
            result.setCode("9999");
        }

        return result;
    }

}
